import Utilitys.Book;
import Utilitys.DruidMySql;
import lombok.SneakyThrows;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.List;

@WebServlet("/books")
public class ServiceBook extends GenericServlet {
    @SneakyThrows
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("<=======Book表单=====>");
        QueryRunner queryRunner = DruidMySql.getQueryRunner();
        String sql = "select * from books";
        List<Book> books = queryRunner.query(sql, new BeanListHandler<>(Book.class));
        books.forEach(System.out::println);
    }
}
